<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加权限</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/layui/layui.js"></script>
    <script src="../../js/jquery.js"></script>
    <script src="../../js/myAjax.js"></script>
</head>
<body>
<div class="layui-form" style="width: 500px">
    <div type="hidden" id="pid"></div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <select name="type" lay-verify="required">
                <option value=""></option>
                <option value="1">菜单</option>
                <option value="2">方法</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限名</label>
        <div class="layui-input-block">
            <input type="text" name="name" required lay-verify="required" placeholder="请输入权限名" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否可用</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="是">
            <input type="radio" name="status" value="0" title="否" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">路径</label>
        <div class="layui-input-block">
            <input type="text" name="src" required lay-verify="required" placeholder="请输入路径" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限值</label>
        <div class="layui-input-block">
            <input type="text" name="value" required lay-verify="required" placeholder="请输入权限值" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">创建时间</label>
        <div class="layui-input-block">
            <input type="text" name="createTime"  required lay-verify="required" id="createTime" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#createTime' //指定元素
            ,type: 'datetime'
            ,format: 'yyyy-MM-dd HH:mm:ss'
        });
    });
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
            let pid=sessionStorage.getItem("pid");
            console.log(data.field);
            let aa = {
                pid:pid,
                name:data.field.name,
                value:data.field.value,
                src:data.field.src,
                type:data.field.type,
                status:data.field.status,
                createTime:data.field.createTime
            };
            console.log(aa);
            let result = myAjax('/permission/add','post',aa);
            if (result.code===200){
                layer.msg("添加成功");
                parent.layer.closeAll();
                parent.location.reload();
            }else {
                layer.msg("添加失败");
            }
            return false;
        });
    });
</script>
</body>
</html>